package cn.edu.zafu.bigdata.psy;

import java.util.ArrayList;
import java.util.List;

class GenericMaxFinder {
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list.isEmpty()) {
            return null;
        }
        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }
}

public class Test3_1 {
    public static void main(String[] args) {
        List<Integer> integerList = new ArrayList<>();
        integerList.add(10);
        integerList.add(5);
        integerList.add(15);
        Integer maxInteger = GenericMaxFinder.findMax(integerList);
        System.out.println("整数列表中的最大值为：" + maxInteger);

        List<String> stringList = new ArrayList<>();
        stringList.add("apple");
        stringList.add("banana");
        stringList.add("cherry");
        String maxString = GenericMaxFinder.findMax(stringList);
        System.out.println("字符串列表中的最大值为：" + maxString);
    }
}
